package cn.edu.hqu.javaee.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

import lombok.Data;

@Data
@Entity
@Table(name="Personal_information")
public class Personal {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	private Date placedAt;
	@NotBlank(message="required")
	private String name;
	@NotBlank(message="M/F")
	private String sex;
	@Pattern(regexp="^\\d{8}$",message="number(8)")
	private String born;
	@Pattern(regexp="^\\d{10}$",message="number(10)")
	private String number;
	@Pattern(regexp="^\\d{4}$",message="number(4)")
	private String grade;
	@NotBlank(message="required")
	private String professional;
	@NotBlank(message="required")
	private String college;
	@ManyToMany(targetEntity=Choose.class)
	private List<Choose> chooses=new ArrayList<>();
	public void addDesign(Choose choose) {
		this.chooses.add(choose);
	}
	@PrePersist
	void placeAt() {
		this.placedAt=new Date();
	}
}
